package com.jsmy.marketing.activity;

import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioGroup;

import com.jsmy.marketing.R;
import com.jsmy.marketing.api.RetrofitManager;
import com.jsmy.marketing.base.BaseActivity;
import com.jsmy.marketing.bean.CustomerBean;
import com.jsmy.marketing.common.Link;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;


/**
 * 学生资料 修改
 */
public class CustomerInfoActivity extends BaseActivity {

    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.edt_add_student_name)
    EditText mEdtName;
    @BindView(R.id.edt_add_student_sex)
    EditText mEdtSex;
    @BindView(R.id.edt_add_student_phone)
    EditText mEdtPhone;
    @BindView(R.id.edt_add_student_rank)
    EditText mEdtRank;//阶段
    @BindView(R.id.edt_add_student_labels)
    EditText mEdtLabels;
    @BindView(R.id.edt_add_student_resoucefrom)
    EditText mEdtResouceFrom;
    @BindView(R.id.edt_add_student_father_phone)
    EditText mEdtFatherPhone;
    @BindView(R.id.edt_add_student_mother_phone)
    EditText mEdtMotherPhone;
    @BindView(R.id.edt_add_student_english_name)
    EditText mEdtEnlishName;
    @BindView(R.id.edt_add_student_wechat)
    EditText mEdtWechat;
    @BindView(R.id.edt_add_student_old)
    EditText mEdtOld;
    @BindView(R.id.edt_add_student_english_level)
    EditText getmEdtEnlishLevel;
    @BindView(R.id.edt_add_student_houseaddress)
    EditText mEdtHouseAddress;
    @BindView(R.id.edt_add_student_school)
    EditText mEdtSchool;

    @BindView(R.id.radioGroup)
    RadioGroup mRadGroup;

    String kid;

    @Override
    protected int resId() {
        return R.layout.activity_student_info;
    }

    @Override
    protected void initData() {
        toolbar.setTitle("");
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        kid=getPrevExtras().getString("kid");
        getkhzlinfo(kid);
    }

    private void getkhzlinfo(String kid) {

        Map<String, Object> map = new HashMap<>();
        map.put("lid", com.jsmy.marketing.manager.UserManager.getInstance().getId());
        map.put("kid", kid);
        mPresenter.loadData(RetrofitManager.getInstance().getkhzlinfo(map), Link.APP_KHZL_INFO);
    }
    @Override
    public void refreshData(Object object, String api_id) {
            switch (api_id){
                case Link.APP_KHZL_INFO:
                    CustomerBean.DataBean bean = ((CustomerBean) object).getData();
                    setCustomerInfo(bean);
                    break;
            }
    }

    private void setCustomerInfo(CustomerBean.DataBean bean) {
        mEdtName.setText(bean.getXm());
//        mEdtRank.setText(bean.getGroupmc());
        mEdtLabels.setText(bean.getPmmc());
        mEdtRank.setText(bean.getJd());
        mEdtPhone.setText(bean.getDh());
        mEdtResouceFrom.setText(bean.getEmail());
        mEdtWechat.setText(bean.getWeixin());
        mEdtOld.setText(bean.getQq());
//        tvTip.setText(bean.getNote());
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_add_customer, menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()){
            case R.id.action_commit://提交


                break;
        }
        return super.onOptionsItemSelected(item);
    }
}
